//
//  Status.swift
//  SinaWeiBo
//
//  Created by gxiangzi on 15/9/6.
//  Copyright © 2015年 hqu. All rights reserved.
//

import UIKit

class Status: NSObject {

    /// 创建时间
    var created_at: String?
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博来源
    var source: String?
    
    /// 配图的 URL 字符串的数组
    var pic_urls: [[String : String]]?

        
    /// 如果原创微博有图，那么转发的微博就没有
    // 被转发的原创微博对象
    var retweeted_status:Status?
    
    // 获得用户的信息
    var user:User?
    
    init(dict:[String:AnyObject])
    {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        
        if key  == "user" {
            // 如果是 key 就调用其内部的方法 转换成一个字典
            user = User(dict: value as! [String : AnyObject])
            return
        }
        
        if key == "retweeted_status" {
            retweeted_status = Status(dict: value as! [String : AnyObject])
            return 
        }
        
        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    override var description: String {
        
        let keys = ["created_at", "id", "text", "source", "user","pic_urls","retweeted_status"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
    
}
